package demo.redisson.service;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Component;


/**
 * spring redis 工具类
 *
 * @author xueyi
 **/
@Component
public class RedisService {

    @Autowired
    private RedissonClient redissonClient;

    private  Integer sn = 0;

    /**
     * 生成编号
     */
    public Integer genSn() {
        RLock lock = redissonClient.getLock("test:redisson");
        try {
            lock.lock();
            sn++;
            System.out.println("-------------------" + sn + "-------------------");
            return sn;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
        return null;
    }


}
